package com.insigma.business.qrcode.soldier.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


@Getter
@Setter
public class AliSshTemplate implements Serializable {

    private static final long serialVersionUID = 648399017515355026L;

    public AliSshTemplate(String templateId, String userId, String url, Map<String, String> contentMap) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("url", url);
        jsonObject.put("action_name", "查看详情");
        jsonObject.put("head_color", "#85be53");

        if (contentMap != null && contentMap.size() > 0) {
            for (Map.Entry<String, String> entry : contentMap.entrySet()) {
                jsonObject.put(entry.getKey(), new ValueObject("#85be53", entry.getValue()));
            }
        }
        this.toUserId = userId;
        this.template = new Template(templateId, jsonObject);
    }

    @JSONField(name = "to_user_id")
    private String toUserId;

    private Template template;

    public static class Template implements Serializable {
        private static final long serialVersionUID = 3031257556880858201L;

        public Template(String templateId, JSONObject context) {
            this.templateId = templateId;
            this.context = context;
        }

        @JSONField(name = "template_id")
        private String templateId;

        private JSONObject context;

        public String getTemplateId() {
            return templateId;
        }

        public void setTemplateId(String templateId) {
            this.templateId = templateId;
        }

        public JSONObject getContext() {
            return context;
        }

        public void setContext(JSONObject context) {
            this.context = context;
        }
    }

    public static class ValueObject implements Serializable {

        private static final long serialVersionUID = -8202719418994994489L;

        public ValueObject(String value) {
            this.value = value;
        }

        public ValueObject(String color, String value) {
            this.color = color;
            this.value = value;
        }

        private String color;

        private String value;

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public static void main(String[] args) {
        Map<String, String> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("a", "a");
        objectObjectHashMap.put("b", "a");
        objectObjectHashMap.put("c", "c");
        AliSshTemplate aliSshTemplate = new AliSshTemplate("tmp", "user", "url", objectObjectHashMap);
        System.out.println(JSON.toJSONString(aliSshTemplate));
    }
}
